﻿/*
create by imaker martin
show the table column by checkbox
*/
(function ($) {

    $.fn.TableColumnSelect = function (options) {
        var selfWrap = this;
        var defaults = {
            listbox: "lisColumtBox", //插入的DIV
            hid: [0]//隐藏的列
        }
        var options = $.extend(defaults, options);



        var cell = options.hid
        var table = this;
       

        var str;
        //var ta = document.createElement('table');
        var ul = document.createElement('ul');

        //jQuery(ta).attr("id", "coumList");
        jQuery(ul).attr({ "id": "coumList", "class": "coumLists" });

        table.find("thead th").each(function (ind) {

            var s = true;
            for (i = 0; i < cell.length; i++) {
                if (cell[i] == ind) {
                    s = false;
                }
            }

            //            if (s) {
            //                var tx = $(this).text();
            //                str = '<tr><td><input onChange=\"CloumEvent(' + ind + ')\" type=\"checkbox\" name=\"col' + ind + '\"  checked=\"checked\"  id =\"inpc' + ind + '\" />';
            //                str = str + '</td><td><label for=\"inpc' + ind + '\" >' + tx + '</lable></td></tr>';
            //                jQuery(ta).append(str);
            //            }


            if (s)
             {
                var tx = $(this).text();
                str = '<li><input onChange=\"CloumEvent(' + ind + ')\" type=\"checkbox\" name=\"col' + ind + '\"  checked=\"checked\"  id =\"inpc' + ind + '\" />';
                str = str + '<label for=\"inpc' + ind + '\" >' + tx + '</lable>';
                jQuery(ul).append(str);
             }

        })
       
        //jQuery(ta).appendTo("#" + options.listbox);
        jQuery(ul).appendTo("#" + options.listbox);
    }

})(jQuery)